package com.punch.common.enums.course;

import org.apache.commons.lang3.StringUtils;

/**
 * @author xiaol
 * @date 2020/7/21 15:53
 * 年级枚举
 */

public enum GradeEnum {
    GRADE_ONE(1, "一年级"),
    GRADE_TWO(2, "二年级"),
    GRADE_THREE(3, "三年级"),
    GRADE_FOUR(4, "四年级"),
    GRADE_FIVE(5, "五年级"),
    GRADE_SIX(6, "六年级");

    GradeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    private int code;
    private String name;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public static String getName(Integer code) {
        if (code == null) {
            return "";
        }
        for (GradeEnum roleEnum : GradeEnum.values()) {
            if (roleEnum.getCode() == code) {
                return roleEnum.getName();
            }
        }
        return "";
    }

    public static int getCode(String name) {

        if (StringUtils.isEmpty(name)) {
            return -1;
        }
        for (GradeEnum roleEnum : GradeEnum.values()) {
            if (roleEnum.getName().equals(name)) {
                return roleEnum.getCode();
            }
        }
        return -1;
    }
}

